package com.zzyl.controller.manager;

import com.zzyl.base.PageBean;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.dto.NursingProjectPageQueryDto;
import com.zzyl.entity.NursingPlan;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nursing/plan")
@Api(tags = "护理计划管理")
@Slf4j
public class NursingPlanController {
    @Autowired
    NursingPlanService nursingPlanService;

    @ApiOperation("根据名称和状态分页查询")
    @GetMapping("/search")
    public ResponseResult<PageBean<NursingPlanVo>> getNursingPlansByPage(NursingProjectPageQueryDto pageQueryDto) {
        log.info("分页查询护理计划");
        PageBean<NursingPlanVo> page = nursingPlanService.getNursingPlansByPage(pageQueryDto);
        return ResponseResult.success(page);
    }

    @ApiOperation("添加护理计划")
    @PostMapping
    public ResponseResult<Void> add(@RequestBody NursingPlanDto nursingPlanDto) {
        log.info("添加护理计划");
        nursingPlanService.add(nursingPlanDto);
        return ResponseResult.success();
    }

    @ApiOperation("根据ID查询护理计划")
    @GetMapping("/{id}")
    public ResponseResult<NursingPlanVo> getById(@PathVariable Long id) {
        log.info("根据ID查询护理计划");
        NursingPlanVo nursingPlanVo = nursingPlanService.read(id);
        return ResponseResult.success(nursingPlanVo);
    }

    @ApiOperation("修改护理计划")
    @PutMapping("/{id}")
    public ResponseResult<Void> update(@PathVariable Long id, @RequestBody NursingPlanDto nursingPlanDto) {
        log.info("修改护理计划");
        nursingPlanService.update(nursingPlanDto);
        return ResponseResult.success();
    }

    @ApiOperation("删除护理计划")
    @DeleteMapping("/{id}")
    public ResponseResult<Void> delete(@PathVariable Long id) {
        log.info("删除护理计划");
        nursingPlanService.delete(id);
        return ResponseResult.success();
    }

    @ApiOperation("启用、禁用护理计划")
    @PutMapping("/{id}/status/{status}")
    public ResponseResult<Void> updateStatus(@PathVariable Long id, @PathVariable Integer status) {
        log.info("启用、禁用护理计划");
        nursingPlanService.updateStatus(id, status);
        return ResponseResult.success();
    }

    @ApiOperation("查询所有护理计划")
    @GetMapping
    public ResponseResult<List<NursingPlan>> getAll() {
        log.info("查询所有护理计划");
        return ResponseResult.success(nursingPlanService.findAll());
    }
}
